<script lang="ts" setup>
import SuperButton from "@/module/button/superButton.vue";
import SuperEditor from "@/module/editor/SuperEditor.vue";
import {useStoryStore} from "@/store/admin/Main/StoryStore.ts";
import router from "@/config/router.ts";
import SuperDialog from "@/module/dialog/superDialog.vue";
import {ref} from "vue";
import Upload from "@/module/upload/upload.vue";
import {Message} from "@/module/message/Message.ts";

const store = useStoryStore()
const editDialog = ref(false)

function info() {
    router.go(-1)
}

function edit() {
    editDialog.value = true
}

async function submit() {
    await store.getApi().edit(store.getStory());
    editDialog.value = false
    Message.success("保存成功")
    await store.initTableData()
    await router.push({path: "/admin/story"})
}
</script>

<template>
    <div style="margin: 10px;">
        <div style="margin-bottom: 10px">
            <super-button title="返回" type="info" @click="info"/>
            <super-button title="发布" type="success" @click="edit"/>
        </div>
        <super-editor v-model="store.getStory().context" height="680"/>
        <super-dialog
                v-model="editDialog"
                title="发布文章"
                width="400"
        >
            <template #context>
                <el-form>
                    <el-form-item label="发布图片">
                        <upload
                                v-model="store.getStory().img"
                                type="image"
                        />
                    </el-form-item>
                    <el-form-item label="发布标题">
                        <el-input
                                v-model="store.getStory().title"
                        />
                    </el-form-item>
                    <el-form-item label="投稿用户">
                        <el-input
                            v-model="store.getStory().name"
                        />
                    </el-form-item>
                    <el-form-item label="投稿时间">
                        <el-date-picker
                            v-model="store.getStory().date"
                            type="date"
                            placeholder="请选择投稿时间"
                            size="large"
                        />
                    </el-form-item>
                    <el-form-item label="内容简介">
                        <el-input
                            v-model="store.getStory().text"
                            type="textarea"
                        />
                    </el-form-item>
                </el-form>
            </template>
            <template #footer>
                <super-button title="返回" type="info" @click="()=>{editDialog = false}"/>
                <super-button title="发布" type="success" @click="submit"/>
            </template>
        </super-dialog>
    </div>
</template>

<style scoped>

</style>